package com.luoyi.service;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * 国际化通用字段修改语句生成
 */
@Slf4j
public class MysqlDdlGenerate {

    final static private List<String> SQL_FORMAT_LIST = ListUtil.of(
            // 公用字段处理
//            "ALTER TABLE {}.{} ADD COLUMN is_active char(1)  DEFAULT 'Y' NULL COMMENT '删除标示';",
//            "ALTER TABLE {}.{} ADD COLUMN created_date datetime(3) NULL COMMENT '创建日期';",
//            "ALTER TABLE {}.{} ADD COLUMN updated_date datetime(3) NULL COMMENT '更新日期';",
//            "ALTER TABLE {}.{} MODIFY COLUMN updated_by varchar(60)  NULL COMMENT '更新人';",
//            "ALTER TABLE {}.{} MODIFY COLUMN created_by varchar(60)  NULL COMMENT '创建人';",
//            "ALTER TABLE {}.{} ADD version int DEFAULT 0 NULL COMMENT '版本';",
//            "ALTER TABLE {}.{} ADD data_org_id varchar(20) NULL COMMENT '数据组织';",
//            "ALTER TABLE {}.{} ADD main_id varchar(20) NULL COMMENT '业务主体';",
//            "ALTER TABLE {}.{} ADD data_node_id varchar(20) NULL COMMENT '数据中心';",
//            "ALTER TABLE {}.{} ADD created_tzone varchar(40) NULL COMMENT '创建时区';",
//            "ALTER TABLE {}.{} ADD updated_tzone varchar(40) NULL COMMENT '更新时区';",
            "ALTER TABLE {}.{} MODIFY enabled enabled1 char(1) DEFAULT 'Y' NULL COMMENT '是否启用';"

            // 删除更新创建时间字段
//            "ALTER TABLE {}.{} DROP COLUMN updated_at;",
//            "ALTER TABLE {}.{} DROP COLUMN created_at;"

            // 修改id字段为varchar(32) 主键
//             "ALTER TABLE {}.{} MODIFY COLUMN id varchar(32) NOT NULL COMMENT '主键';"
    );

    public static String generate(String schema, String table, List<String> sqlFormatList) {
        StringBuilder sb = new StringBuilder();
        for (String sqlFormat : sqlFormatList) {
            String format = StrUtil.format(sqlFormat, schema, table);
            sb.append(format).append("\n");
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        String schema = "mpaas_ovs_dynamic_form";
        List<String> tables = ListUtil.of(
            "dynamic_form_field",
            "dynamic_form_table",
            "dynamic_form_data_source",
            "dynamic_form_application",
            "dynamic_form_template",
            "dynamic_form_template_button",
            "dynamic_form_template_field",
            "dynamic_form_template_node",
            "dynamic_form_table_association",
            "dynamic_form_template_version"
        );
        tables.forEach(table -> {
            System.out.println(generate(schema, table, SQL_FORMAT_LIST));
        });
    }






}
